//package com.example.demo.itemProcessor;
//
//import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
//import org.springframework.batch.item.database.JdbcPagingItemReader;
//import org.springframework.batch.item.database.Order;
//import org.springframework.batch.item.database.support.MySqlPagingQueryProvider;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.jdbc.core.RowMapper;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import javax.sql.DataSource;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.util.HashMap;
//import java.util.Map;
//@EnableBatchProcessing
//@Configuration
//@Component("processorMyReader1")
//public class ProcessorReaderFromDatabase {
//    @Resource
//    private DataSource dataSource;
//    @Bean
//    public JdbcPagingItemReader<Customer> processorMyReader() {
//        JdbcPagingItemReader<Customer> reader = new JdbcPagingItemReader<Customer>();
//        reader.setDataSource(dataSource);
//        reader.setFetchSize(100);
//        reader.setRowMapper(new RowMapper<Customer>() {
//            @Override
//            public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
//                Customer customer = new Customer();
//                customer.setId(rs.getInt(1));
//                customer.setFirstName(rs.getString(2));
//                customer.setLastName(rs.getString(3));
//                customer.setBirthday(rs.getString(4));
//                return customer;
//            }
//        });
//
//        //指定sql语句
//        MySqlPagingQueryProvider provider = new MySqlPagingQueryProvider();
//        provider.setSelectClause("id,firstName,lastName,birthday");
//        provider.setFromClause("from customer");
//
//        //指定根据哪个字段排序
//        Map<String, Order> sort = new HashMap<>();
//        sort.put("id",Order.ASCENDING);
//        provider.setSortKeys(sort);
//
//        reader.setQueryProvider(provider);
//        return reader;
//    }
//}
